class Admin::ProductCategoriesController < Admin::BaseController

  before_filter :find_product


  def new
    @categories = Category.all
    @product_category = @product.product_categories.new
  end


  def create
    @product_category = @product.product_categories.new(params[:product_category])
    @success = @product_category.save
      
    respond_to do |respond|
      respond.html do
        if !@success
          render :action => 'new'
        else
          redirect_to edit_admin_product_path( @product )
        end
      end
      
      respond.js
    end

  end

  def destroy
    @product_category = @product.product_categories.find(params[:id])
    @success = @product_category.destroy

    respond_to do |respond|
      respond.html do
        if @success
          flash[:notice] = 'Product is uit categorie verwijderd.'
        else
          flash[:notice] = 'Product is niet uit categorie verwijderd.'
        end

        redirect_to edit_admin_product_path( @product )
      end

      respond.js
    end
  end


  private
    def find_product
      @product = Product.find(params[:product_id])
    end
end
